package com.example.zy5_project_jetpack.mvp.view.FindFragment.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CenterInside;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.zy5_project_jetpack.R;
import com.example.zy5_project_jetpack.mvp.view.FindFragment.Bean.RecommentBean;

import java.util.ArrayList;
import java.util.List;

public class ReCommentAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<RecommentBean.DataBeanX.DataBean> dataBeans = new ArrayList<>();

    public ReCommentAdapter(Context context) {
        this.context = context;
    }

    public void addReCommentList(List<RecommentBean.DataBeanX.DataBean> dataBeans) {
        this.dataBeans.addAll(dataBeans);
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.comment_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tv_ReComment_title.setText(dataBeans.get(position).getTitle());
        viewHolder.tv_ReComment_text.setText(dataBeans.get(position).getIntro());
        RequestOptions options=new RequestOptions();
        options.transform(new RoundedCorners(10));
        Glide.with(context).load(dataBeans.get(position).getIcon()).apply(options).into(viewHolder.iv_image_ReComment);
    }

    @Override
    public int getItemCount() {
        return dataBeans.size();
    }

    public static
    class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public ImageView iv_image_ReComment;
        public TextView tv_ReComment_title;
        public TextView tv_ReComment_text;
        public TextView btn_like;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.iv_image_ReComment = (ImageView) rootView.findViewById(R.id.iv_image_ReComment);
            this.tv_ReComment_title = (TextView) rootView.findViewById(R.id.tv_ReComment_title);
            this.tv_ReComment_text = (TextView) rootView.findViewById(R.id.tv_ReComment_text);
            this.btn_like = (TextView) rootView.findViewById(R.id.btn_like);
        }

    }
}
